package com.johnzer.frame.utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorRes;
import android.support.annotation.DimenRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;

import com.johnzer.frame.app.BaseApp;


public class ResUtils {

    public static String getString(@StringRes int res) {
        return BaseApp.instance().getResources().getString(res);
    }

    public static int getColor(@ColorRes int res) {
        return BaseApp.instance().getResources().getColor(res);
    }

    /**
     * 从资源ID获得dimen的大小
     *
     * @param dimenId
     * @return
     */
    public static int getDimen(@DimenRes int dimenId) {
        return BaseApp.instance().getResources()
                .getDimensionPixelSize(dimenId);
    }

    /**
     * 从资源ID获得Drawable
     *
     * @param resId
     * @return
     */
    public static Drawable getDrawable(@DrawableRes int resId) {
        return BaseApp.instance().getResources()
                .getDrawable(resId);
    }

    // ************************************* 根据
    // 资源名获取id***************************/
    public static int getLayoutId(String paramString) {
        Context paramContext = BaseApp.instance();
        return paramContext.getResources().getIdentifier(paramString, "layout",
                paramContext.getPackageName());
    }

    public static int getStringId(String paramString) {
        Context paramContext = BaseApp.instance();
        return paramContext.getResources().getIdentifier(paramString, "string",
                paramContext.getPackageName());
    }

    public static int getDrawableId(String paramString) {
        Context paramContext = BaseApp.instance();
        return paramContext.getResources().getIdentifier(paramString,
                "drawable", paramContext.getPackageName());
    }

    public static int getStyleId(String paramString) {
        Context paramContext = BaseApp.instance();
        return paramContext.getResources().getIdentifier(paramString, "style",
                paramContext.getPackageName());
    }

    public static int getId(String paramString) {
        Context paramContext = BaseApp.instance();
        return paramContext.getResources().getIdentifier(paramString, "id",
                paramContext.getPackageName());
    }

    public static int getColorId(String paramString) {
        Context paramContext = BaseApp.instance();
        return paramContext.getResources().getIdentifier(paramString, "color",
                paramContext.getPackageName());
    }

    public static int getArrayId(String paramString) {
        Context paramContext = BaseApp.instance();
        return paramContext.getResources().getIdentifier(paramString, "array",
                paramContext.getPackageName());
    }
}
